/**
 * API接口统一管理
 */
import http from './request';

// 基础URL
const BASE_API = 'https://m1.apifoxmock.com/m1/6102433-5793108-default';


// 用户相关接口
export const userApi = {
  // 登录
  login: (data) => http.post('/admin/login', data),
  // 注册
  register: (data) => http.post('/admin/register', data),
  // 获取用户信息
  getUserInfo: () => http.get('/admin/info'),
  
  //验证码
  getVerificationCode: (data) => http.post('/admin/verification-code', data),
  // 更新用户信息
  updateUserInfo: (data) => http.put('/admin/info', data),
  // 修改密码
  changePassword: (data) => http.post('/admin/change-password', data),
  // 重置密码
  resetPassword: (data) => http.post('/admin/reset-password', data)
};

// 商品相关接口
export const productApi = {
  // 获取商品列表
  getProductList: (params) => http.get('/goods/list', params),
  // 获取商品详情
  getProductDetail: (id) => http.get(`/goods/details/${id}`),
  // 获取推荐商品
  getRecommendProducts: (params) => http.get('/goods/recommend', params),
  // 获取商品分类
  getCategories: () => http.get('/goods/categories'),
  // 获取分类商品
  getCategoryProducts: (categoryId, params) => http.get(`/goods/category/${categoryId}`, params),
  // 搜索商品
  searchProducts: (keyword, params) => http.get('/goods/search', { keyword, ...params }),
  // 商品购买
  buyProduct: (data) => http.post('/goods/shop', data)
};

// 购物车相关接口
export const cartApi = {
  // 获取购物车列表
  getCartList: () => http.get('/cart/list'),
  // 添加商品到购物车
  addToCart: (data) => http.post('/cart/add', data),
  // 更新购物车商品数量
  updateCartItem: (data) => http.put('/cart/update', data),
  // 删除购物车商品
  removeCartItem: (ids) => http.delete('/cart/remove', { ids }),
  // 清空购物车
  clearCart: () => http.delete('/cart/clear')
};

// 订单相关接口
export const orderApi = {
  // 创建订单
  createOrder: (data) => http.post('/admin/order/create', data),
  // 获取订单列表
  getOrderList: (params) => http.get('/admin/order/list', params),
  // 获取订单详情
  getOrderDetail: (id) => http.get(`/admin/order/${id}`),
  // 取消订单
  cancelOrder: (id) => http.put(`/admin/order/cancel/${id}`),
  // 确认收货
  confirmOrder: (id) => http.put(`/admin/order/confirm/${id}`),
  // 删除订单
  deleteOrder: (id) => http.delete(`/admin/order/delete/${id}`)
};

// 地址相关接口
export const addressApi = {
  // 获取地址列表
  getAddressList: () => http.get('/admin/address/list'),
  // 获取地址详情
  getAddressDetail: (id) => http.get(`/admin/address/detail/${id}`),
  // 添加地址
  addAddress: (data) => http.post('/admin/address/add', data),
  // 更新地址
  updateAddress: (data) => http.put('/admin/address/update', data),
  // 删除地址
  deleteAddress: (id) => http.delete(`/admin/address/delete/${id}`),
  // 设置默认地址
  setDefaultAddress: (id) => http.put(`/admin/address/set-default/${id}`)
};

// 音乐相关接口
export const musicApi = {
  // 获取音乐
  getMusic: (id) => http.get(`/music/get/${id}`),
  // 添加音乐
  addMusic: (data) => http.post('/music/inster', data),
  // 删除音乐
  deleteMusic: (id) => http.delete('/music/delete', { id })
}; 